unit Class_USER;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TUSER=class(TUniEngine)
  private
    FUSERINDX : Integer;
    FWHOBUILD : Integer;
    FUSEREXID : Integer;
    FHASHCODE : Integer;
    FPARENTID : Integer;
    FDATALEVL : Integer;
    FDATASTAT : Integer;
    FDATAORDR : Integer;
    FDATADATE : Integer;
    FDATATIME : Extended;
    FKJNDKJQJ : Integer;
    FMASTINDX : Integer;
    FMASTWHOB : Integer;
    FUSERCODE : string;
    FUSERNAME : string;
    FUSERMEMO : string;
    FUSERADDR : string;
    FDCONTACT : string;
    FWCONTACT : string;
    FUSERDATE : Integer;
    FUSERSEXV : Integer;
    FUSERBORN : Integer;
    FUSERIDCD : string;
    FUSERCARD : string;
    FDISCOUNT : Extended;
    FINTMONEY : Extended;
    FUSERCOIN : Extended;
    FUSERPSWD : string;
    FUNITREAL : Integer;
    FLOFTREAL : Integer;
    FWORKCODE : string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    //#function  GetNextIndx:Integer;overload;
    //#function  GetNextIndx(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;
  published
    property USERINDX : Integer read FUSERINDX  write FUSERINDX;
    property WHOBUILD : Integer read FWHOBUILD  write FWHOBUILD;
    property USEREXID : Integer read FUSEREXID  write FUSEREXID;
    property HASHCODE : Integer read FHASHCODE  write FHASHCODE;
    property PARENTID : Integer read FPARENTID  write FPARENTID;
    property DATALEVL : Integer read FDATALEVL  write FDATALEVL;
    property DATASTAT : Integer read FDATASTAT  write FDATASTAT;
    property DATAORDR : Integer read FDATAORDR  write FDATAORDR;
    property DATADATE : Integer read FDATADATE  write FDATADATE;
    property DATATIME : Extended read FDATATIME  write FDATATIME;
    property KJNDKJQJ : Integer read FKJNDKJQJ  write FKJNDKJQJ;
    property MASTINDX : Integer read FMASTINDX  write FMASTINDX;
    property MASTWHOB : Integer read FMASTWHOB  write FMASTWHOB;
    property USERCODE : string read FUSERCODE  write FUSERCODE;
    property USERNAME : string read FUSERNAME  write FUSERNAME;
    property USERMEMO : string read FUSERMEMO  write FUSERMEMO;
    property USERADDR : string read FUSERADDR  write FUSERADDR;
    property DCONTACT : string read FDCONTACT  write FDCONTACT;
    property WCONTACT : string read FWCONTACT  write FWCONTACT;
    property USERDATE : Integer read FUSERDATE  write FUSERDATE;
    property USERSEXV : Integer read FUSERSEXV  write FUSERSEXV;
    property USERBORN : Integer read FUSERBORN  write FUSERBORN;
    property USERIDCD : string read FUSERIDCD  write FUSERIDCD;
    property USERCARD : string read FUSERCARD  write FUSERCARD;
    property DISCOUNT : Extended read FDISCOUNT  write FDISCOUNT;
    property INTMONEY : Extended read FINTMONEY  write FINTMONEY;
    property USERCOIN : Extended read FUSERCOIN  write FUSERCOIN;
    property USERPSWD : string read FUSERPSWD  write FUSERPSWD;
    property UNITREAL : Integer read FUNITREAL  write FUNITREAL;
    property LOFTREAL : Integer read FLOFTREAL  write FLOFTREAL;
    property WORKCODE : string read FWORKCODE  write FWORKCODE;
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AUSER:TUSER):TUSER;overload;
    class procedure CopyIt(AUSER:TUSER;var Result:TUSER);overload;
  end;

implementation

{ TUSER }
procedure TUSER.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('USER_INDX').Value := USERINDX;
        ParamByName('WHO_BUILD').Value := WHOBUILD;
        ParamByName('USER_EXID').Value := USEREXID;
        ParamByName('HASH_CODE').Value := HASHCODE;
        ParamByName('PARENT_ID').Value := PARENTID;
        ParamByName('DATA_LEVL').Value := DATALEVL;
        ParamByName('DATA_STAT').Value := DATASTAT;
        ParamByName('DATA_ORDR').Value := DATAORDR;
        ParamByName('DATA_DATE').Value := DATADATE;
        ParamByName('DATA_TIME').Value := DATATIME;
        ParamByName('KJND_KJQJ').Value := KJNDKJQJ;
        ParamByName('MAST_INDX').Value := MASTINDX;
        ParamByName('MAST_WHOB').Value := MASTWHOB;
        ParamByName('USER_CODE').Value := USERCODE;
        ParamByName('USER_NAME').Value := USERNAME;
        ParamByName('USER_MEMO').Value := USERMEMO;
        ParamByName('USER_ADDR').Value := USERADDR;
        ParamByName('D_CONTACT').Value := DCONTACT;
        ParamByName('W_CONTACT').Value := WCONTACT;
        ParamByName('USER_DATE').Value := USERDATE;
        ParamByName('USER_SEXV').Value := USERSEXV;
        ParamByName('USER_BORN').Value := USERBORN;
        ParamByName('USER_IDCD').Value := USERIDCD;
        ParamByName('USER_CARD').Value := USERCARD;
        ParamByName('DIS_COUNT').Value := DISCOUNT;
        ParamByName('INT_MONEY').Value := INTMONEY;
        ParamByName('USER_COIN').Value := USERCOIN;
        ParamByName('USER_PSWD').Value := USERPSWD;
        ParamByName('UNIT_REAL').Value := UNITREAL;
        ParamByName('LOFT_REAL').Value := LOFTREAL;
        ParamByName('WORK_CODE').Value := WORKCODE;
      end;
      otEdit:
      begin
        ParamByName('USER_INDX').Value := USERINDX;
        ParamByName('WHO_BUILD').Value := WHOBUILD;
        ParamByName('USER_EXID').Value := USEREXID;
        ParamByName('HASH_CODE').Value := HASHCODE;
        ParamByName('PARENT_ID').Value := PARENTID;
        ParamByName('DATA_LEVL').Value := DATALEVL;
        ParamByName('DATA_STAT').Value := DATASTAT;
        ParamByName('DATA_ORDR').Value := DATAORDR;
        ParamByName('DATA_DATE').Value := DATADATE;
        ParamByName('DATA_TIME').Value := DATATIME;
        ParamByName('KJND_KJQJ').Value := KJNDKJQJ;
        ParamByName('MAST_INDX').Value := MASTINDX;
        ParamByName('MAST_WHOB').Value := MASTWHOB;
        ParamByName('USER_CODE').Value := USERCODE;
        ParamByName('USER_NAME').Value := USERNAME;
        ParamByName('USER_MEMO').Value := USERMEMO;
        ParamByName('USER_ADDR').Value := USERADDR;
        ParamByName('D_CONTACT').Value := DCONTACT;
        ParamByName('W_CONTACT').Value := WCONTACT;
        ParamByName('USER_DATE').Value := USERDATE;
        ParamByName('USER_SEXV').Value := USERSEXV;
        ParamByName('USER_BORN').Value := USERBORN;
        ParamByName('USER_IDCD').Value := USERIDCD;
        ParamByName('USER_CARD').Value := USERCARD;
        ParamByName('DIS_COUNT').Value := DISCOUNT;
        ParamByName('INT_MONEY').Value := INTMONEY;
        ParamByName('USER_COIN').Value := USERCOIN;
        ParamByName('USER_PSWD').Value := USERPSWD;
        ParamByName('UNIT_REAL').Value := UNITREAL;
        ParamByName('LOFT_REAL').Value := LOFTREAL;
        ParamByName('WORK_CODE').Value := WORKCODE;
      end;
      otDelt:
      begin
        ParamByName('USER_INDX').Value := USERINDX;
        ParamByName('WHO_BUILD').Value := WHOBUILD;
        ParamByName('USER_EXID').Value := USEREXID;

      end;
    end;
  end;
end;

function TUSER.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_USER',['USER_INDX',USERINDX,'WHO_BUILD',WHOBUILD,'USER_EXID',USEREXID],AUniConnection);
end;

{#function TUSER.GetNextIndx: Integer;
begin

end;}

{#function TUSER.GetNextIndx(AUniConnection: TUniConnection): Integer;
begin

end;}

function TUSER.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_USER WHERE   USER_INDX=:USER_INDX AND WHO_BUILD=:WHO_BUILD AND USER_EXID=:USER_EXID';
end;

function TUSER.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_USER'
         +'    ( USER_INDX, WHO_BUILD, USER_EXID, HASH_CODE, PARENT_ID'
         +'    , DATA_LEVL, DATA_STAT, DATA_ORDR, DATA_DATE, DATA_TIME'
         +'    , KJND_KJQJ, MAST_INDX, MAST_WHOB, USER_CODE, USER_NAME'
         +'    , USER_MEMO, USER_ADDR, D_CONTACT, W_CONTACT, USER_DATE'
         +'    , USER_SEXV, USER_BORN, USER_IDCD, USER_CARD, DIS_COUNT'
         +'    , INT_MONEY, USER_COIN, USER_PSWD, UNIT_REAL, LOFT_REAL'
         +'    , WORK_CODE)'
         +'    VALUES'
         +'    (:USER_INDX,:WHO_BUILD,:USER_EXID,:HASH_CODE,:PARENT_ID'
         +'    ,:DATA_LEVL,:DATA_STAT,:DATA_ORDR,:DATA_DATE,:DATA_TIME'
         +'    ,:KJND_KJQJ,:MAST_INDX,:MAST_WHOB,:USER_CODE,:USER_NAME'
         +'    ,:USER_MEMO,:USER_ADDR,:D_CONTACT,:W_CONTACT,:USER_DATE'
         +'    ,:USER_SEXV,:USER_BORN,:USER_IDCD,:USER_CARD,:DIS_COUNT'
         +'    ,:INT_MONEY,:USER_COIN,:USER_PSWD,:UNIT_REAL,:LOFT_REAL'
         +'    ,:WORK_CODE)';
end;

function TUSER.GetStrsIndex: string;
begin
  Result:=Format('%D-%D-%D',[USERINDX,WHOBUILD,USEREXID]);
end;

function TUSER.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_USER SET'
         +'    HASH_CODE=:HASH_CODE,'
         +'    PARENT_ID=:PARENT_ID,'
         +'    DATA_LEVL=:DATA_LEVL,'
         +'    DATA_STAT=:DATA_STAT,'
         +'    DATA_ORDR=:DATA_ORDR,'
         +'    DATA_DATE=:DATA_DATE,'
         +'    DATA_TIME=:DATA_TIME,'
         +'    KJND_KJQJ=:KJND_KJQJ,'
         +'    MAST_INDX=:MAST_INDX,'
         +'    MAST_WHOB=:MAST_WHOB,'
         +'    USER_CODE=:USER_CODE,'
         +'    USER_NAME=:USER_NAME,'
         +'    USER_MEMO=:USER_MEMO,'
         +'    USER_ADDR=:USER_ADDR,'
         +'    D_CONTACT=:D_CONTACT,'
         +'    W_CONTACT=:W_CONTACT,'
         +'    USER_DATE=:USER_DATE,'
         +'    USER_SEXV=:USER_SEXV,'
         +'    USER_BORN=:USER_BORN,'
         +'    USER_IDCD=:USER_IDCD,'
         +'    USER_CARD=:USER_CARD,'
         +'    DIS_COUNT=:DIS_COUNT,'
         +'    INT_MONEY=:INT_MONEY,'
         +'    USER_COIN=:USER_COIN,'
         +'    USER_PSWD=:USER_PSWD,'
         +'    UNIT_REAL=:UNIT_REAL,'
         +'    LOFT_REAL=:LOFT_REAL,'
         +'    WORK_CODE=:WORK_CODE'
         +'    WHERE USER_INDX=:USER_INDX'
         +'    AND   WHO_BUILD=:WHO_BUILD'
         +'    AND   USER_EXID=:USER_EXID';
end;

constructor TUSER.Create;
begin

end;

destructor TUSER.Destroy;
begin

  inherited;
end;

class function TUSER.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TUSER.Create;
  TUSER.ReadDS(AUniQuery,Result);
end;

class procedure TUSER.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TUSER(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=UpperCase(Field.FieldName);
      if FieldName='USER_INDX' then
      begin
        USERINDX :=Field.AsInteger;
      end else
      if FieldName='WHO_BUILD' then
      begin
        WHOBUILD :=Field.AsInteger;
      end else
      if FieldName='USER_EXID' then
      begin
        USEREXID :=Field.AsInteger;
      end else
      if FieldName='HASH_CODE' then
      begin
        HASHCODE :=Field.AsInteger;
      end else
      if FieldName='PARENT_ID' then
      begin
        PARENTID :=Field.AsInteger;
      end else
      if FieldName='DATA_LEVL' then
      begin
        DATALEVL :=Field.AsInteger;
      end else
      if FieldName='DATA_STAT' then
      begin
        DATASTAT :=Field.AsInteger;
      end else
      if FieldName='DATA_ORDR' then
      begin
        DATAORDR :=Field.AsInteger;
      end else
      if FieldName='DATA_DATE' then
      begin
        DATADATE :=Field.AsInteger;
      end else
      if FieldName='DATA_TIME' then
      begin
        DATATIME :=Field.AsFloat;
      end else
      if FieldName='KJND_KJQJ' then
      begin
        KJNDKJQJ :=Field.AsInteger;
      end else
      if FieldName='MAST_INDX' then
      begin
        MASTINDX :=Field.AsInteger;
      end else
      if FieldName='MAST_WHOB' then
      begin
        MASTWHOB :=Field.AsInteger;
      end else
      if FieldName='USER_CODE' then
      begin
        USERCODE :=Field.AsString;
      end else
      if FieldName='USER_NAME' then
      begin
        USERNAME :=Field.AsString;
      end else
      if FieldName='USER_MEMO' then
      begin
        USERMEMO :=Field.AsString;
      end else
      if FieldName='USER_ADDR' then
      begin
        USERADDR :=Field.AsString;
      end else
      if FieldName='D_CONTACT' then
      begin
        DCONTACT :=Field.AsString;
      end else
      if FieldName='W_CONTACT' then
      begin
        WCONTACT :=Field.AsString;
      end else
      if FieldName='USER_DATE' then
      begin
        USERDATE :=Field.AsInteger;
      end else
      if FieldName='USER_SEXV' then
      begin
        USERSEXV :=Field.AsInteger;
      end else
      if FieldName='USER_BORN' then
      begin
        USERBORN :=Field.AsInteger;
      end else
      if FieldName='USER_IDCD' then
      begin
        USERIDCD :=Field.AsString;
      end else
      if FieldName='USER_CARD' then
      begin
        USERCARD :=Field.AsString;
      end else
      if FieldName='DIS_COUNT' then
      begin
        DISCOUNT :=Field.AsFloat;
      end else
      if FieldName='INT_MONEY' then
      begin
        INTMONEY :=Field.AsFloat;
      end else
      if FieldName='USER_COIN' then
      begin
        USERCOIN :=Field.AsFloat;
      end else
      if FieldName='USER_PSWD' then
      begin
        USERPSWD :=Field.AsString;
      end else
      if FieldName='UNIT_REAL' then
      begin
        UNITREAL :=Field.AsInteger;
      end else
      if FieldName='LOFT_REAL' then
      begin
        LOFTREAL :=Field.AsInteger;
      end else
      if FieldName='WORK_CODE' then
      begin
        WORKCODE :=Field.AsString;
      end;
    end
  end;
end;

class function  TUSER.CopyIt(AUSER: TUSER): TUSER;
begin
  Result:=TUSER.Create;
  TUSER.CopyIt(AUSER,Result)
end;

class procedure TUSER.CopyIt(AUSER:TUSER;var Result:TUSER);
begin
  if Result=nil then Exit;
  Result.USERINDX :=AUSER.USERINDX;
  Result.WHOBUILD :=AUSER.WHOBUILD;
  Result.USEREXID :=AUSER.USEREXID;
  Result.HASHCODE :=AUSER.HASHCODE;
  Result.PARENTID :=AUSER.PARENTID;
  Result.DATALEVL :=AUSER.DATALEVL;
  Result.DATASTAT :=AUSER.DATASTAT;
  Result.DATAORDR :=AUSER.DATAORDR;
  Result.DATADATE :=AUSER.DATADATE;
  Result.DATATIME :=AUSER.DATATIME;
  Result.KJNDKJQJ :=AUSER.KJNDKJQJ;
  Result.MASTINDX :=AUSER.MASTINDX;
  Result.MASTWHOB :=AUSER.MASTWHOB;
  Result.USERCODE :=AUSER.USERCODE;
  Result.USERNAME :=AUSER.USERNAME;
  Result.USERMEMO :=AUSER.USERMEMO;
  Result.USERADDR :=AUSER.USERADDR;
  Result.DCONTACT :=AUSER.DCONTACT;
  Result.WCONTACT :=AUSER.WCONTACT;
  Result.USERDATE :=AUSER.USERDATE;
  Result.USERSEXV :=AUSER.USERSEXV;
  Result.USERBORN :=AUSER.USERBORN;
  Result.USERIDCD :=AUSER.USERIDCD;
  Result.USERCARD :=AUSER.USERCARD;
  Result.DISCOUNT :=AUSER.DISCOUNT;
  Result.INTMONEY :=AUSER.INTMONEY;
  Result.USERCOIN :=AUSER.USERCOIN;
  Result.USERPSWD :=AUSER.USERPSWD;
  Result.UNITREAL :=AUSER.UNITREAL;
  Result.LOFTREAL :=AUSER.LOFTREAL;
  Result.WORKCODE :=AUSER.WORKCODE;
end;

end.

